<template>
  <div class="page-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="15">
        <el-form inline :model="queryForm" @submit.prevent>
          <el-form-item label="资产名称">
            <el-input
              v-model.trim="queryForm.name"
              clearable
              placeholder="请输入名称"
            />
          </el-form-item>
          <el-form-item>
            <el-button :icon="Search" type="primary" @click="queryData">
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-left-panel>
    </vab-query-form>

    <el-table v-loading="listLoading" border :data="list">
      <el-table-column
        type="index"
        width="60"
        header-align="center"
        align="center"
        label="序号"
      />
      <el-table-column
        label="名称"
        prop="name"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="资产分类"
        prop="cateName"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="状态"
        prop="statusName"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="所属部门"
        prop="deptName"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <!--      <el-table-column-->
      <!--        label="分配人"-->
      <!--        prop="updateByName"-->
      <!--        show-overflow-tooltip-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--      />-->
      <el-table-column
        label="价格"
        prop="price"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="备注"
        prop="comment"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="创建人"
        prop="createByName"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="创建时间"
        prop="createTime"
        show-overflow-tooltip
        header-align="center"
      />
      <el-table-column
        label="更新人"
        prop="updateByName"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="更新时间"
        prop="updateTime"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <!--      <el-table-column-->
      <!--        label="操作"-->
      <!--        width="200"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--      >-->
      <!--        <template #default="{ row }">-->
      <!--          <el-button text type="primary" @click="handleDetail(row)">-->
      <!--            详情-->
      <!--          </el-button>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <template #empty>
        <el-empty class="vab-data-empty" description="暂无数据" />
      </template>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
  </div>
</template>

<script>
  import { getMeAssetInfoList } from '@/api/assetManagement'
  import { Delete, Plus, Search } from '@element-plus/icons-vue'
  export default defineComponent({
    name: 'MyAssetList',
    setup() {
      const router = useRouter()
      const state = reactive({
        editRef: null,
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          name: '',
          status: '',
          pageNum: 1,
          pageSize: 10,
        },
        statusList: [
          {
            label: '闲置中',
            value: 0,
          },
          {
            label: '使用中',
            value: 1,
          },
          {
            label: '报废',
            value: 2,
          },
        ],
      })

      const setSelectRows = (val) => {
        state.selectRows = val
      }

      const handleDetail = (row) => {
        router.push(`/asset/assetManagementDetail?id=${row.id}`)
      }
      const handleSizeChange = (val) => {
        state.queryForm.pageSize = val
        fetchData()
      }
      const handleCurrentChange = (val) => {
        state.queryForm.pageNum = val
        fetchData()
      }
      const queryData = () => {
        state.queryForm.pageNum = 1
        fetchData()
      }
      const fetchData = async () => {
        try {
          state.listLoading = true
          const { data } = await getMeAssetInfoList(state.queryForm)
          state.list = data.list
          state.total = data.total
          state.listLoading = false
        } catch (e) {
          console.log(e)
        }
      }
      onMounted(() => {
        fetchData()
      })

      return {
        ...toRefs(state),
        setSelectRows,
        handleSizeChange,
        handleCurrentChange,
        queryData,
        fetchData,
        handleDetail,
        Delete,
        Plus,
        Search,
      }
    },
  })
</script>

<style scoped>
  .toolbar {
    margin-bottom: 4px;
  }
</style>
